/*
 * @Author: szx
 * @Date: 2022-02-24 13:11:27
 * @LastEditTime: 2022-02-24 13:16:57
 * @Description:
 * @FilePath: \leetcode\200-299\202\202_2.js
 */
/**
 * @param {number} n
 * @return {boolean}
 */
var isHappy = function (n) {
    const set = new Set();
    let sum = 0;
    while (true) {
        sum = 0;
        while (n) {
            sum += (n % 10) * (n % 10);
            n = Math.floor(n / 10);
        }
        if (sum == 1) return true;
        if (set.has(sum)) return false;
        set.add(sum);
        n = sum;
    }
};
